#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# Project: spd-sxmcc
"""
@author: lyndon
@time Created on 2018/11/30 9:49
@desc
"""
import requests
import os

root = 'D:/ETL/img/'
m = 0
img_url = 'https://mmbiz.qpic.cn/mmbiz_jpg/EAod0piaMaFODCiatRpWE5rZ5vGdydUeGhowSiaYzgHru89ibo0p2IPwwicY63lMRAV9dPiasmkCV7BJT6l3Gv6cRA7A/640?wx_fmt=jpeg&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1'

# path = root + img_url.split('/')[-1]
path = root + 'mmbiz.webp'

print(path)
#
# # try:
if not os.path.exists(root):
    os.mkdir(root)
if not os.path.exists(path):
    r = requests.get(img_url)
    headers = r.headers
    print(headers)

    content_type = headers['Content-Type']
    application_type, subtype = content_type.split('/')
    print(application_type, subtype)
    with open(path, 'wb') as f:
        f.write(r.content)
        f.close()
        print("图片保存成功")
else:
    print("保存失败")
# # except Exception as e:
# #     print("爬取失败", e)
